<?php
/** 业务类的接口 */
interface BusinessService
{
    public function doProcessing();
}

class EJBService implements BusinessService
{
    public function doProcessing()
    {
        echo "Processing task by invoking EJB Service";
    }
}
class JMSService implements BusinessService
{
    public function doProcessing()
    {
       echo "Processing task by invoking JMS Service";
    }
}

/** 查找具体的业务 */
class BusinessLookUp
{
    /** @return BusinessService */
    public function getBusinessService($type)
    {
        if(strtoupper($type) === "EJB"){
            return new EJBService();
        }
        else{
            return new JMSService();
        }
    }
}

/** 代替client执行业务 */
class BusinessDelegate {
    /** @var BusinessLookUp $lookup */
    protected $lookup = null;
    /** @var BusinessService $business */
    protected $business = null;
    protected $type = "";
    public function __construct()
    {
        $this->lookup = new BusinessLookUp;
    }
    public function setServiceType($type)
    {
        $this->type = $type;
        return $this;
    }
    public function doTask()
    {
        $business = $this->lookup->getBusinessService($this->type);
        $business->doProcessing();
    }
}

$delegate = new BusinessDelegate;
$delegate->setServiceType("EJB")->doTask();
